package net.flintx.array;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class PascalTriangle {
    public List<List<Integer>> generate(int numRows) {
        /**
         * generate
         *
         * @Description:
         *  Given numRows, generate the first numRows of Pascal's triangle.
         * @Example:
         *  Input: numRows = 5
         *  Output:
         *      [
         *          [1],
         *          [1,1],
         *          [1,2,1],
         *          [1,3,3,1],
         *          [1,4,6,4,1]
         *      ]
         * @Params: [numRows]
         * @Return: List<List<Integer>>
         * @Date: 2018/1/7
         */

        Integer[][] nums = new Integer[numRows][numRows];
        for (int i = 0; i < numRows; i++) {
            nums[i][0] = 1;
            nums[i][i] = 1;
        }
        for (int i = 1; i < numRows; i++) {
            for (int j = 1; j < i; j++) {
                nums[i][j] = nums[i - 1][j - 1] + nums[i - 1][j];
            }
        }
        List<List<Integer>> res = new ArrayList<>();
        for (int i = 0; i < numRows; i++) {
            List<Integer> temp = new ArrayList<>();
            temp.addAll(Arrays.asList(nums[i]).subList(0, i + 1));
            res.add(temp);
        }
        return res;
    }

    public static void main(String[] args) {
        int numRows = 5;
    }
}
